
/** An American state which - for the purpose of the senate - 
 * has a name, a population size and a number of seats.
 * 
 * @author Team Turtle 
 *
 */
public class State implements Comparable<Object> {
	private String name; 
	private int population, chairs;

	public State(String name, int population) {
		this.name = name;
		this.population = population;
		
		chairs = 1;	// initial allotment
	}

	public String getName() {
		return name;
	}
	
	/**
	 * 
	 * @param name  The name of this state
	 */
	public void setName(String name) {
		this.name = name;
	}

	public int getPopulation() {
		return population;
	}

	/**
	 * 
	 * @param population The size of this population
	 */
	public void setPopulation(int population) {
		this.population = population;
	}

	//
	public int getChairs() {
		return chairs;
	}

	// increments the number of chairs
	public void incChairs() {
		chairs++;
	}

	@Override
	/** Implementation  of Comparable interface.
	 * ( compares population sizes. Huntington Hill method. )
	 * 
	* @param 0  the state-object to compare against.
	* @return  -1 if this state has the smaller population.
	*  			1 if this state has a bigger population and 
	*  			0 if they are the same size.
	*/
	public int compareTo(Object o) {
		State other = (State) o;

		// priority value 1
		double pvThis, pvOther;
		
		pvThis = population / Math.sqrt(chairs * (chairs + 1));
		
		pvOther = other.getPopulation()
				/ (Math.sqrt(other.getChairs() * (other.getChairs() + 1)));

		if (pvThis < pvOther) {
			return -1;
		} else if (pvThis > pvOther) {
			return 1;
		} else {
			return 0;
		}
	}
	
	/** compare number of seats to that of another state.
	 *  ( used for sorting states )
	 * 
	 * @param  other  Another state.
	 * @return  false if other state has fewer seats, 
	 * 			true if other state has more seats.
	*/
	public boolean less(State other){
		return chairs < other.getChairs();		
	} 
	

}
